import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:ywn_app/moudle/entity/MovieDetails.dart';

class Movie extends StatelessWidget {
  final String id;
  final String title;
  final String posterSmall;
  final String sourceName;
  final String duration;
  final String fmplaycnt;
  final String fmlike;
  final String playUrl;
  final String publishTime;
  final String fmplaycnt2;

  Movie(
      {Key key,
      this.id,
      this.duration,
      this.title,
      this.fmlike,
      this.fmplaycnt,
      this.playUrl,
      this.fmplaycnt2,
      this.posterSmall,
      this.publishTime,
      this.sourceName})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: (){
        Navigator.push(context,MaterialPageRoute(builder: (BuildContext context) => MovieDetails(
          id: this.id,
          playUrl: this.playUrl,
          title: this.title,
          publishTime:this.publishTime,
          fmplaycnt: this.fmplaycnt,
          fmplaycnt2:this.fmplaycnt2,
          fmlike: this.fmlike,
        )));
      },
      child: Wrap(
        direction: Axis.horizontal,
        textDirection: TextDirection.ltr,
        children: <Widget>[
          AspectRatio(
            aspectRatio: 3 / 2,
            child: Container(
                alignment: Alignment.bottomCenter,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.vertical(top: Radius.circular(5)),
                  image: DecorationImage(
                    image: NetworkImage(posterSmall),
                    fit: BoxFit.cover,
                  ),
                ),
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.end,
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: <Widget>[
                    BottomTitle(icon: Icons.remove_red_eye, title: fmplaycnt),
                    BottomTitle(icon: Icons.favorite_border, title: fmlike),
                    BottomTitle(icon: Icons.access_time, title: duration)
                  ],
                )),
          ),
          Container(
            alignment: Alignment.centerLeft,
            color: Colors.white,
            padding: EdgeInsets.all(2),
            child: Text(
              '$title\n',
              textAlign: TextAlign.start,
              maxLines: 2,
              overflow: TextOverflow.ellipsis,
              style: TextStyle(fontSize: 12),
            ),
          ),
          Container(
            decoration: BoxDecoration(
              borderRadius: BorderRadius.vertical(bottom: Radius.circular(5)),
              color: Colors.white,
            ),
            padding: EdgeInsets.only(left: 2,right: 2,bottom: 2),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                Flexible(
                  child: Text(
                    sourceName,
                    textAlign: TextAlign.start,
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(
                        fontWeight: FontWeight.w500,
                        fontSize:12, color: Colors.black38),
                  ),
                ),
                Icon(
                  Icons.more_vert,
                  color: Colors.black38,
                  size: 14,
                )
              ],
            ),
          )
        ],
      ),
    );
  }
}

class BottomTitle extends StatelessWidget {
  String title;
  IconData icon;

  BottomTitle({Key key, this.icon, this.title}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Row(
        children: <Widget>[
          Icon(icon, size: ScreenUtil().setSp(24), color: Colors.white),
          SizedBox(
            width: ScreenUtil().setWidth(1),
          ),
          Text(
            title,
            style: TextStyle(
                color: Colors.white, fontSize: ScreenUtil().setSp(24)),
          )
        ],
      ),
    );
  }
}
